import { CACHE_USERINFO, CACHE_TOKEN, CACHE_EXPIRES_TIME } from '../../config.js';
import Util from '../../utils/util.js';
import { getLogo } from '../../api/api.js';
import { login } from '../../api/user.js';

let app = getApp();

Component({
    properties: {
        windowShow: {
            type: Boolean,
            value: false,
        },
        modalData: {
            type: Object,
            value: {},
        },
    },
    data: {
        to_content: '',
        wechat_number: '',
        qq_number: '',
        to_name: '',
        birthday: '',
    },
    observers: {
        'modalData': function(modalData) {
            console.log('modalData---->', modalData);
            if (modalData.to_content) {
                this.setData({
                    to_content: modalData.to_content,
                    wechat_number: modalData.wechat_number,
                    qq_number: modalData.qq_number,
                    to_name: modalData.to_name,
                    birthday: modalData.birthday,
                })
            }
        },
    },
    attached() {

    },
    ready() {
        console.log('this.data.modalData---->', this.data.modalData);
        

    },
    methods: {
        close() {
            this.setData({
                windowShow: true
            });
        },
        submit() {
            let { to_content, wechat_number, qq_number, to_name, birthday } = this.data;
            if ([to_content, wechat_number, qq_number, to_name, birthday].includes('')) {
                app.Tips({ title: '请检查信息！' });
                return
            }
            let data = {
                to_content,
                wechat_number,
                qq_number,
                to_name,
                birthday
            };
            this.triggerEvent('SubmitWindow', data);
            this.setData({
                windowShow: true
            });
        },
        dateChange(e) {
            let data = e.detail.value.split("-");
            let _data = data.join("");
            this.setData({ birthday: _data });
        },
        bindHideKeyboard: function(e) {
            switch (e.currentTarget.dataset.name) {
                case 'to_content':
                    this.setData({
                        to_content: e.detail.value,
                    })
                    break;
                case 'wechat_number':
                    this.setData({
                        wechat_number: e.detail.value,
                    })
                    break;
                case 'qq_number':
                    this.setData({
                        qq_number: e.detail.value,
                    })
                    break;
                case 'to_name':
                    this.setData({
                        to_name: e.detail.value,
                    })
                    break;
                default:
                    break;
            }
        },
    },
})